/**
 * Created by iwm on 2017/3/2.
 */
$(document).ready(function () {
    $("#add_confirm").unbind('click').click(function () {
        var options = {
            url: '/common/addComicfansExperience',
            beforeSubmit: validate,  // pre-submit callback
            success: showResponse,  // post-submit callback
            dataType: 'json',
            type: 'post',
        };
        $("#addForm").ajaxSubmit(options);
    });

    $(".delrecommand").each(function () {
        $(this).click(function () {
            var id = $(this).parent().parent().find("td").eq(0).text();
            console.log(id)
            $("#deleteModal").modal("show");
            $("#delete_confirm").unbind('click').click(function () {
                //$("#deleteModal").modal("hide");
                $.ajax({
                    url: '/common/updateComicfansExperience',
                    timeout: 100000,
                    type: 'post',
                    dataType: 'json',
                    data: {
                        'id': id,
                        'status': 1
                    },
                    success: function (rs) {
                        if (rs.errno != 0) {
                            toastr.error(rs.errmsg, '', {positionClass: 'toast-bottom-center'});
                        } else {
                            toastr.success(rs.errmsg);
                            window.location.reload();
                        }
                    },
                    error: function () {
                        toastr.error('系统错误', '', {positionClass: 'toast-bottom-center'});
                    }
                });
            });
        });
    });

    function validate(formData) {
        for (var i = 0; i < formData.length; i++) {
            if (!formData[i].value) {
                toastr.error('请输入所有选项', '', {positionClass: 'toast-bottom-center'});
                return false;
            }
        }
    }

    function showResponse(responseText) {
        //console.log(responseText);
        if (0 !== responseText.errno) {
            toastr.error(responseText.errmsg, '', {positionClass: 'toast-bottom-center'});
        }
        else {
            toastr.success('增加成功', '', {positionClass: 'toast-bottom-center'});
            $('#addrecommand').modal('hide');
            window.location.reload();
        }
    }


});